﻿#include "Chamfer.h"
// core
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
//framework
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
//python
#include "FITK_Kernel/FITKPython/FITKPythonInterface.h"
//operator
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include "OperatorsInterface/ParaWidgetInterfaceOperator.h"
//interface
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoCommandList.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKGeoInterfaceFactory.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelOperSolid.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelSphere.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoMultiDelete.h"
//component
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelSolid.h"
#include "FITK_Component/FITKGeoCompOCC/FITKOCCModelOperSolid.h"
#include <QMetaEnum>
#include <QDebug>

Chamfer::Chamfer(int id /*= 0*/)
{
    if (id == 0) return;
    m_command = wTools.getGeoCommand(Interface::FITKGeoEnum::FITKGeometryComType::FGTChamferSolid);
    if (!m_command) wTools.updateExecutionStatus(false);
    else m_Chamfer = dynamic_cast<Interface::FITKAbsGeoModelChamferSolid*>(m_command);
}

Chamfer::Chamfer(Interface::FITKAbsGeoModelChamferSolid* chamfer)
{
    m_command = m_Chamfer = chamfer;
}

const QString Chamfer::getClassName()
{
    return "Chamfer";
}

bool Chamfer::setInputCmdId(int cmdId)
{
    if (!m_Chamfer) return false;
    m_Chamfer->setInputCmdId(cmdId);
    return true;
}

bool Chamfer::setDistance(double dis)
{
    if (!m_Chamfer) return false;
    m_Chamfer->setDistance(dis);
    return true;
}

ChamferWrapper::ChamferWrapper()
{
}

Chamfer* ChamferWrapper::new_Chamfer()
{
    return new Chamfer(-1);
}

void ChamferWrapper::delete_Chamfer(Chamfer* obj)
{
    if (obj) delete obj;
}

void ChamferWrapper::setInputCmdName(Chamfer* obj, const QString& name)
{
    auto data = geoCmdUndoList->getDataByName(name);
    bool flag = data;
    if (data) obj->setInputCmdId(data->getDataObjectID());
    wTools.updateExecutionStatus(flag);
}

void ChamferWrapper::setEdgeIndice(Chamfer* obj, QList<int> indexs)
{
    auto chamfer = dynamic_cast<Interface::FITKAbsGeoModelChamferSolid*>(obj->getCommand());
    bool flag = chamfer;
    wTools.updateExecutionStatus(flag);
    if (!flag) return;
    QList<Interface::VirtualShape> vShapes;
    for (int i = 0; i < indexs.size(); i++)
    {
        Interface::VirtualShape vShape(-1, indexs[i]);
        vShapes.append(vShape);
    }
    chamfer->setEdgeTopos(vShapes);
}

void ChamferWrapper::setDistance(Chamfer* obj, double dis)
{
    if (obj == nullptr) return;
    obj->setDistance(dis);
}

void ChamferWrapper::update(Chamfer* obj)
{
    auto chamfer = dynamic_cast<Interface::FITKAbsGeoModelChamferSolid*>(obj->getCommand());

    // 执行操作器刷新命令。
    auto m_Operator = FITKOPERREPO->getOperatorT<EventOper::ParaWidgetInterfaceOper>("actionChamferSolid");

    // 传递输入参数。
    m_Operator->setArgs("InputCmdId", chamfer->getInputCmdId());
    m_Operator->setArgs("InputEdgeIndice", QVariant::fromValue(chamfer->getEdgeTopos()));
    m_Operator->setArgs("InputDistance", chamfer->getDistance());

    // 执行功能。
    bool flag = m_Operator->execProfession();
    wTools.updateExecutionStatus(flag);

    // 获取数据ID。
    int histId = -1;
    if (flag && m_Operator->argValue("Id", histId))
        registerSig(obj, histId, "delete");
}

Chamfer* ChamferWrapper::static_Chamfer_Create()
{
    return new_Chamfer();
}
